/*
 * @(#)TextTagger.java	0.9 08/01/07
 *
 * Copyright 2007 Fabio Gasparetti. All rights reserved.
 */

package org.tabularium.text.nlp;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * Provides a simple common interface for POST/NER taggers.
 * 
 * @author Fabio Gasparetti
 * @version 0.9, 08/01/07
 */
public abstract class TextTagger {
	/**
	 * The Tag array is ordered according to the following criteria:
	 * <ul>
	 * <li>start index
	 * <li>length (shorter first)
	 * <li>type (lexicographicly)
	 * </ul>
	 * 
	 * @param text
	 * @return
	 * @throws Exception
	 */
	public abstract Tag[] tag(String text) throws Exception;
	
	/**
	 * Returns the sublist of tags that are contained in the given tag.
	 * 
	 * @param t1
	 * @return
	 */
	public static Tag[] filter(Tag[] tags, String type) {
		ArrayList l1 = new ArrayList();
		for (int i = 0; i < tags.length; i++) {			
			if (type.compareToIgnoreCase(tags[i].type) == 0) 
				l1.add(tags[i]);
		}
		return (Tag[])l1.toArray(new Tag[] {});
	}		
	
	/**
	 * Returns the sublist of tags that are contained in the given pos.
	 * 
	 * @param t1
	 * @return
	 */
	public static Tag[] filter(Tag[] tags, int pos) {
		ArrayList l1 = new ArrayList();
		for (int i = 0; i < tags.length; i++) {			
			if (pos == tags[i].pos) 
				l1.add(tags[i]);
		}
		return (Tag[])l1.toArray(new Tag[] {});
	}		
		
	/**
	 * Returns the sublist of tags that are contained in the given tag.
	 * 
	 * @param t1
	 * @return
	 *//*
	public static List[] filter(List tags, int[] pos) {
		ArrayList l1 = new ArrayList();
		Iterator iter = tags.iterator();
		while (iter.hasNext()) {
			Tag t = (Tag)iter.next();
			if (type.compareToIgnoreCase(t.type) == 0) 
				l1.add(t);
		}
		return l1;		
	}	*/		 
}
